package com.hxc.common.utils;

import org.slf4j.Logger;
import org.springframework.stereotype.Component;

@Component
public class LogHelper {
    /**
     * 写异常日志
     * @param e 异常原因
     */
    public static void writeLog(Exception e, Logger logger) {
        try {

            StackTraceElement[] st = e.getStackTrace();
            for (StackTraceElement stackTraceElement : st) {

                String exclass = stackTraceElement.getClassName();
                String method = stackTraceElement.getMethodName();
                if(exclass.startsWith("com.ht")){
                    logger.error("\n [类:" + exclass + "]调用"
                            + method + "时在第" + stackTraceElement.getLineNumber()
                            + "行代码处发生异常!异常类型:" + e.getClass().getName()+"信息:"+e.getMessage());
                    logger.error("\n");
                }
            }
        } catch (Exception e2) {
            // TODO: handle exception
        }

    }
}
